package com.ruiboyun.liveapp.util.tool;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

/**
 * Created by 吴世芊 on 2016/11/24.
 * Update by  on
 * 公司:杭州无尽信息科技有限公司
 * 邮箱：apple9302@126.com
 * Description:
 */

public class AnimationUtils {
    //抖动动画CycleTimes动画重复的次数
    public static  void shakeAnimation(int CycleTimes, ImageView view) {
        Animation translateAnimation = new TranslateAnimation(0, 6, 0, 6);
        translateAnimation.setInterpolator(new CycleInterpolator(CycleTimes));
        translateAnimation.setDuration(1000);
        view.setAnimation(translateAnimation);
    }

    public static  Animation shakeAnimation(int CycleTimes) {
        Animation translateAnimation = new TranslateAnimation(0, 6, 0, 6);
        translateAnimation.setInterpolator(new CycleInterpolator(CycleTimes));
        translateAnimation.setDuration(1000);
        return translateAnimation;
    }
    public static void loadInAnimation(View topLayout,View time){
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(topLayout, "translationY", -topLayout.getBottom(), 0);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(topLayout, "alpha", 0, 1);
        AnimatorSet set = new AnimatorSet();
        set.setDuration(500).playTogether(objectAnimator, alpha);
        set.setInterpolator(new AccelerateInterpolator());
        set.setStartDelay(100);
        ObjectAnimator objectAnimator1=ObjectAnimator.ofFloat(time,"translationX",-time.getRight(),0);
        ObjectAnimator alphaTime=ObjectAnimator.ofFloat(time,"alpha",0,1);
        AnimatorSet set2=new AnimatorSet();
        set2.setDuration(500).playTogether(objectAnimator1,alphaTime);
        set2.setInterpolator(new AccelerateInterpolator());
        set2.setStartDelay(100);
        set2.start();
        set.start();


    }

    public static void loadOutAnimation(View topLayout,View time){
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(topLayout, "translationY", 0, -topLayout.getBottom());
        ObjectAnimator alpha = ObjectAnimator.ofFloat(topLayout, "alpha", 1, 0);
        AnimatorSet set = new AnimatorSet();
        set.setDuration(500).playTogether(objectAnimator, alpha);
        set.setInterpolator(new AccelerateDecelerateInterpolator());
        ObjectAnimator objectAnimator1=ObjectAnimator.ofFloat(time,"translationX",0,-time.getRight());
        ObjectAnimator alphaTime=ObjectAnimator.ofFloat(time,"alpha",1,0);
        AnimatorSet set2=new AnimatorSet();
        set2.setDuration(500).playTogether(objectAnimator1,alphaTime);
        set2.setInterpolator(new AccelerateDecelerateInterpolator());
        set2.start();
        set.start();

    }
    /**
     * 定义从右侧进入的动画效果
     *
     * @return
     */
    public static Animation inFromRightAnimation() {
        Animation inFromRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromRight.setDuration(200);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        return inFromRight;
    }

    /**
     * 定义从左侧退出的动画效果
     *
     * @return
     */
    public static Animation outToLeftAnimation() {
        Animation outtoLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoLeft.setDuration(200);
        outtoLeft.setInterpolator(new AccelerateInterpolator());
        return outtoLeft;
    }

    /**
     * 定义从左侧进入的动画效果
     *
     * @return
     */
    public static Animation inFromLeftAnimation() {
        Animation inFromLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromLeft.setDuration(200);
        inFromLeft.setInterpolator(new AccelerateInterpolator());
        return inFromLeft;
    }
    /**
     * 定义从右侧退出时的动画效果
     *
     * @return
     */
    public static Animation outToRightAnimation() {
        Animation outtoRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoRight.setDuration(200);
        outtoRight.setInterpolator(new AccelerateInterpolator());
        return outtoRight;
    }

}
